package com.frinder.base.advisor;

import com.frinder.base.global.Result;
import com.frinder.base.global.ResultGenerator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @ClassName GlobalExceptionControllerAdvice
 * @Author frinder
 * @Description controller 全局异常处理类
 * @Date 2019/1/19 16:25
 * @Version 1.0
 */
@Order(9)
@ControllerAdvice
public class GlobalExceptionControllerAdvice {

    private final Logger logger = LoggerFactory.getLogger(getClass());

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result errorHandler(HttpServletRequest request, Exception e) {
        logger.error(e.getMessage(), e);
        return ResultGenerator.genFailResult(request.getRequestURL().toString(), e.getMessage());
    }


}
